export default async function (ctx) {
  // 路径
  var domain = `https://${ctx.req.headers.host}`
  // 截取路径第二参数
  let headRole = ''
  let urlArr = ctx.url ? ctx.url.split('/') : []
  urlArr.forEach((item, index) => {
    if (item != '' && index < 2) {
      headRole = item
    }
  })
  ctx.config = {
    domain,
    headRole,
    ip: ctx.req.headers['x-real-ip'] || '',
    navData: [{
      title: '首页',
      href: `${domain}/`,
      on: false
    }, {
      title: '网站建设',
      href: `${domain}/wzjs/`,
      on: false
    }, {
      title: '网站优化',
      href: `${domain}/wzyh/`,
      on: false
    }, {
      title: '竞价托管',
      href: `${domain}/jjtg/`,
      on: false
    }, {
      title: '抖音运营',
      href: `${domain}/dyyy/`,
      on: false
    }, {
      title: '客户案例',
      href: `${domain}/khal/`,
      on: false
    }, {
      title: '新闻资讯',
      href: `${domain}/xwzx/`,
      on: false
    }, {
      title: '联系我们',
      href: `${domain}/lxwm/`,
      on: false
    }],
    bannerData: [{
      id: 1,
      src: 'https://ys-cc.oss-cn-chengdu.aliyuncs.com/upload/20221118/a7d2a3de55be45cbacd2e2bd8b5c793c.png',
      href: `${domain}/wzjs/`,
      title: '网站建设'
    }, {
      id: 2,
      src: 'https://ys-cc.oss-cn-chengdu.aliyuncs.com/upload/20221118/b399ef2b9499402caaa38dad1a22b57a.png',
      href: `${domain}/wzyh/`,
      title: '网站优化'
    }, {
      id: 3,
      src: 'https://ys-cc.oss-cn-chengdu.aliyuncs.com/upload/20221118/4cd3dd361e9548cb87e3b577a33c7bc0.png',
      href: `${domain}/dyyy/`,
      title: '抖音运营'
    }, {
      id: 4,
      src: 'https://ys-cc.oss-cn-chengdu.aliyuncs.com/upload/20221118/35926473848f48299a45f7c1a26daa82.png',
      href: `${domain}/khal/`,
      title: '客户案例'
    }, {
      id: 5,
      src: 'https://ys-cc.oss-cn-chengdu.aliyuncs.com/upload/20221118/0989ea78f1d9418e8c2c340dcbc1f69b.png',
      href: `${domain}/jjtg/`,
      title: '竞价托管'
    }]
  }

  // error.vue
  ctx.store.state.config = ctx.config

  // 检测到手机端时重定向
  var userAgent = ctx.req.headers['user-agent'];
  if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(userAgent)) {
    ctx.redirect(`https://m.fangyangkj.com${ctx.route.fullPath}`)
  }
}